package com.ftg.learn.service.impl;

import com.ftg.learn.common.dto.LoginDto;
import com.ftg.learn.common.util.JwtUtil;
import com.ftg.learn.common.util.R;
import com.ftg.learn.remote.AuthRemote;
import com.ftg.learn.service.AuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.LinkedHashMap;

/**
 * @author 布衣
 */
@Service
public class UserServiceImplCopy implements AuthService {

    @Autowired
    AuthRemote authRemote;

    private final String TOKEN_KEY = "token@123";

    @Override
    public R<String> loginAndToken(LoginDto loginDto) {
        R<LinkedHashMap> userInfo = authRemote.callSystemUserLogin(loginDto);
        if (userInfo != null && userInfo.getCode().equals(200)) {
            String token = JwtUtil.generateJWT(JwtUtil.keyPair.getPrivate(), userInfo.getData());
            return R.build(200, "登陆成功", token);
        }
        return R.build(500, "登陆失败", null);
    }

}
